﻿using System;
/*
 *  We are given 5 integer numbers. Write a program 
 *  that checks if the sum of some subset of them is 0.
 *  Example: 3, -2, 1, 1, 8  1+1-2=0.
 */

class SubsetEqualsZero
    {
        static void Main(string[] args)
        {

            int[] integersArray = { 3, -2, -2, -3, 4 };

            Console.WriteLine("Initial set: [{0}, {1}, {2}, {3}, {4}] ", integersArray[0], integersArray[1]
                              , integersArray[2], integersArray[3], integersArray[4]);
            for (int i = 0; i < integersArray.Length; i++)
            {
                for (int j = i+1; j < integersArray.Length; j++)
                {
                    //check for subsets with 2 members
                    if ((integersArray[i] + integersArray[j]) == 0)
                    {
                        Console.WriteLine("Substet that equals zero: [{0} , {1}]",integersArray[i],integersArray[j]);
                    }

                    for (int k = j+1; k < integersArray.Length; k++)
                    {
                        //check for subsets with 3 members
                        if ((integersArray[i] + integersArray[j] + integersArray[k]) == 0)
                        {
                            Console.WriteLine("Substet that equals zero: [{0} , {1} , {2}]", integersArray[i], integersArray[j],integersArray[k]);
                        }
                        
                        for (int l = k+1; l < integersArray.Length; l++)
                        {
                            //check for subsets with 4 members
                            if ((integersArray[i] + integersArray[j] + integersArray[k] + integersArray[l]) == 0)
                            {
                                Console.WriteLine("Substet that equals zero: [{0} , {1} , {2} , {3}]", integersArray[i], integersArray[j], integersArray[k],integersArray[l]);
                            }
                        }
                    }
                }
            }
        }
    }
